<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use lxs\api\ApiResponse;
use lxs\tools\AuthToken as AuthTokenTools;
use Symfony\Component\HttpFoundation\Response;

class WebToken
{
    /**
     * Handle an incoming request.
     *
     * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        $authToken = new AuthTokenTools();
        if ($authToken->checkToken() === false) {
            return ApiResponse::apiResponseData(100, 'token验证失败');
        }
        $request->web_uid = (int)$authToken->getUid();
        return $next($request);
    }
}
